﻿using BasicInformation.ApiRead.Application.Command.IType;
using BasicInformation.Domain;
using BasicInformation.ErrorCode;
using BasicInformation.Infrastructure.Implement;
using MediatR;
using System.Text;

namespace BasicInformation.ApiRead.Application.Handler.IType
{
    public class GetITypeHandler : IRequestHandler<GetITypeCommand, ApiPaging<ITypeModel>>
    {
        private readonly ILogger<GetITypeHandler> logger;
        private readonly DatabaseContext db;

        public GetITypeHandler(ILogger<GetITypeHandler> logger, DatabaseContext db)
        {
            this.logger = logger;
            this.db = db;
        }
        public async Task<ApiPaging<ITypeModel>> Handle(GetITypeCommand request, CancellationToken cancellationToken)
        {
            ApiPaging<ITypeModel> result = new ApiPaging<ITypeModel>();
            StringBuilder sql = new StringBuilder();
            StringBuilder countSql = new StringBuilder();

            sql.Append(@"		SELECT ITypeId,ITypeName FROM itypemodel");
            var res = db.SqlSugar.Queryable<ITypeModel>();
            result.Data = res.ToList();
            result.Code = ApiEnum.OK;
            result.Msg = "盘点类型查询成功";
            logger.LogInformation(result.Msg);
            return await Task.FromResult(result);
        }
    }
}